import axios from 'axios'
import env from '../../build/env'

const ajaxUrl = env === 'development'
  ? 'http://hospital.jianwenw.me/manage/'
  : env === 'production'
    ? 'https://www.url.com'
    : 'http://hospital.jianwenw.me/manage/'

let util = {
  uploadUrl: '',
  //  分页配置信息
  pageInfo: {
    pageSize: 1
  },
  ajaxUrl: ajaxUrl
}

/*
util.ajax = axios.create({
  baseURL: ajaxUrl,
  timeout: 30000
})
*/
util.title = function (title) {
  title = title || 'Imp Cloud Manage'
  window.document.title = 'Manage|' + title
};

util.inOf = function (arr, targetArr) {
  let res = true
  arr.forEach(item => {
    if (targetArr.indexOf(item) < 0) {
      res = false
    }
  })
  return res
}

util.oneOf = function (ele, targetArr) {
  if (targetArr.indexOf(ele) >= 0) {
    return true
  } else {
    return false
  }
}

util.isEmpty = function (item) {
  if (item === null || item === '' || item === 'undefined' || item.length === 0) {
    return true
  } else {
    return false
  }
}
/*
util.contains = function (arr, obj) {
  let i = arr.length
  while (i--) {
    if (arr[i] === obj) {
      return true
    }
  }
  return false
}
*/

//  将json字符串转为json对象
util.jsonParse = function (data) {
  return JSON.parse(data)
}
//  将json对象转为字符串
util.jsonStringify = function (data) {
  return JSON.stringify(data)
}
export default util
